<?php
namespace Macaca\Module\Admin;

use Monkey;

class Main {

    /**
     * @var \Monkey\App
     */
    public $app;

    /**
     * @param Monkey\App $app
     */
    public function __construct($app) {
        $this->app = $app;
    }

    /**
     * @return array
     */
    public function getServerInfo() {

        $user = new User($this->app);
        $data['uname'] = $user->getFieldFromSession('uname');
        $data['last_ip'] = $user->getFieldFromSession('last_ip');

        $data['server_os'] = PHP_OS;
        $data['server_ip'] = $_SERVER['HTTP_HOST'];
        $data['time'] = date('Y-m-d H:i:s', $this->app->TIME);
        $data['web_server'] = $_SERVER['SERVER_SOFTWARE'];

        $data['php_version'] = PHP_VERSION;
        $data['monkey_version'] = Monkey\App::MONKEY_VERSION;
        $data['image_support'] = extension_loaded('gd') ? '√' : 'X';
        $data['session_support'] = ini_get('session.save_handler') ? '√' : 'X';
        $data['memory_size'] = ceil(memory_get_usage() / 1024);
        $data['upload_limit'] = ini_get('upload_max_filesize');
        $data['post_limit'] = ini_get('post_max_size');
        $data['timeout'] = ini_get('max_execution_time');

        $data['macaca_version'] = $this->app->VERSION;

        return $data + $this->getWarning();
    }

    public function getWarning() {
        $data['warning'] = false;
        $data['warning_msg'] = '程序有更新，请下载并更新!';
        return $data;
    }
} 